<?php 
	include("../includes/connect_db.php");

	$bill = (isset($_POST["bill"])) ? $_POST["bill"] : "" ;
	$idresto = (isset($_POST["idresto"])) ? $_POST["idresto"] : "" ;
?>

<?php if ($bill == 1) { ?>
<ul class="breadcrumb well">
	<button class="btn btn-success new-bill f1" <?php echo $disable_split ?>>
		<i class="fa fa-plus"></i>
		Split Bill (F1)
	</button>
	<button class="btn change-focus f4" disabled>
		<i class="fa fa-random"></i>
		Change Focus (F4)
	</button>
</ul>
<?php } ?>

<?php  
	$sql_cover = "SELECT * FROM nota WHERE idresto = '$idresto' AND bill = '$bill'";
	$query_cover = mysql_query($sql_cover);
	if (mysql_num_rows($query_cover) > 0) {
		echo "<div class='cover'></div>";
	}
?>

<div class="alert alert-info">Invoice <?php echo $bill ?></div>
<div id="bill-detail" class="bill-container bill-focus" data-bill="<?php echo $bill; ?>">
	<table class="table table-striped">
		<thead>
			<tr>
				<th>No</th>
				<th>Menu</th>
				<th>Quantity</th>
				<th>Price</th>
				<th>Total</th>
			</tr>
		</thead>
		<tbody>
			<?php 
				$i = 1; 
				$total = 0;
				$sql_resto_menu = "SELECT * FROM resto_menu WHERE idresto = '$idresto' AND bill = '$bill'";
				$query_resto_menu = mysql_query($sql_resto_menu);
				while ($resto_menu = mysql_fetch_array($query_resto_menu)) {
			?>
			<tr class="resto_menu" data-id="<?php echo $resto_menu["id"] ?>">
				<td><?php echo $i ?></td>
				<td class="td-menu" data-menu="<?php echo $resto_menu[idmenu]; ?>">
					<?php  
						$sql_menu = "SELECT * FROM menu WHERE id = '$resto_menu[idmenu]'";
						$query_menu = mysql_query($sql_menu);
						$menu = mysql_fetch_array($query_menu);
						echo $menu['nama'];
					?>
				</td>
				<td class="td-jumlah" data-jumlah="<?php echo $resto_menu["jumlah"]; ?>"><?php echo $resto_menu["jumlah"]; ?></td>
				<td class="td-harga" data-harga="<?php echo $resto_menu["harga"] ?>"><?php echo $resto_menu["harga"] ?></td>
				<td class="td-total"><?php echo $resto_menu["jumlah"] * $resto_menu["harga"]; ?></td>
			</tr>
			<?php
					$harga_total = $resto_menu["jumlah"] * $resto_menu["harga"];
					$total = $total + $harga_total;
					$i++;
				}
			?>
		</tbody>
		<tfoot>
			<?php
				$sql_setting = "SELECT * FROM setting";
				$query_setting = mysql_query($sql_setting);
				$setting = mysql_fetch_array($query_setting);
				$tax_service = $setting["tax"] + $setting["service"];
			?>
			<tr style="font-weight: bold">
				<td colspan="4" style="text-align: right;">Tax ( <?php echo $setting["tax"] ?>% ) & Service ( <?php echo $setting["service"] ?>% )</td>
				<td class="tax_service"><?php echo $total * $tax_service / 100 ?></td>
			</tr>
			<tr style="font-weight: bold">
				<td colspan="4" style="text-align: right;">Grand Total</td>
				<td class="grand_total"><?php echo $total + ($total * $tax_service / 100); ?></td>
			</tr>
		</tfoot>
	</table>
</div>

<ul class="breadcrumb well">
	<?php if ($bill != 1) { ?>
		<button class="btn btn-danger del-bill f9">
			<i class="fa fa-trash-o"></i>
			Delete Bill (F9)
		</button>
	<?php } ?>
	<button class="btn btn-inverse payment f6">
		Payment (F6)
	</button>
	<button class="btn print-bill f7">
		Print Bill (F7)
	</button>
</ul>

<script type="text/javascript">
	$(document).ready(function() {
		$('.td-harga, .td-total, .tax_service, .grand_total').autoNumeric('init', {
			aSign: 'IDR ',
			aPad: false
		});
	});
</script>